//
//  UIViewController+navigationItem.m
//  BimaMatrix
//
//  Created by Aimeow on 4/24/15.
//  Copyright (c) 2015 Aimeow. All rights reserved.
//

#import "UIViewController+navigationItem.h"


@implementation UIViewController (navigationItem)

- (void)setNavigationItemLeftWithTitle : (NSString *)title leftButtonClicked : (VoidCompletionBlock)block
{
    BmButton* item = BmButton.new;
    
    [item setTitle:title forState:UIControlStateNormal];
    [item setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [item sizeToFit];
    [item bk_whenTapped:^{
        block();
    }];
    [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:item] animated:YES];
}

- (void)setNavigationItemRightWithTitle : (NSString *)title rightButtonClicked : (VoidCompletionBlock)block
{
    BmButton* item = BmButton.new;
    
    [item setTitle:title forState:UIControlStateNormal];
    [item setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [item sizeToFit];
    [item bk_whenTapped:^{
        block();
    }];
    [self.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithCustomView:item] animated:YES];
}

- (void)setNavigationItemLeftWithImage : (UIImage *)image leftButtonClicked : (VoidCompletionBlock)block
{
    UIButton* item = [UIButton buttonWithType:UIButtonTypeCustom];
    [item setBackgroundImage:image forState:UIControlStateNormal];
    item.frame = CGRectMake(0, 0, 40, 20);
    [item bk_whenTapped:^{
        block();
    }];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:item];
}

- (void)setNavigationItemRightWithImage : (UIImage *)image rightButtonClicked : (VoidCompletionBlock)block
{
    UIButton* item = [UIButton buttonWithType:UIButtonTypeCustom];
    [item setBackgroundImage:image forState:UIControlStateNormal];
    item.frame = CGRectMake(0, 0, 40, 20);
    [item bk_whenTapped:^{
        block();
    }];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:item];
}

- (void)setNavigationTitleImage : (UIImage *)image
{
    UIImageView* titleView = [[UIImageView alloc]initWithImage:image];
    
    self.navigationItem.titleView = titleView;
}

@end
